<template>
  <view>
    <!-- <Head :regularDetail='regularDetail'></Head> -->
    <Car :regularDetail="regularDetail"></Car>
    <Tubiao :regularMinuteProduct="regularMinuteProduct" :time="time"></Tubiao>
    <view class="fenlei" style="margin-top: 40rpx">
      <view
        :class="item.code == true ? 'xuanzhong' : ''"
        style="border-left: 0px"
        v-for="(item, index) in codetext"
        @click="change(item)"
        :key="index"
        >{{ item.t }}</view
      >
    </view>

    <view class="texts"
      >风险提示：本产品为净值型产品，本金与收益随实际投资运作浮动，长期持有收益稳健，但短期有波动，可能出现亏损</view
    >
    <view class="but" @click="bought(ids, name)"> 立即购买 </view>
  </view>
</template>

<script>
import Head from "../../components/hutubiao/heads.vue";
import Car from "../../components/hutubiao/car.vue";
import Tubiao from "../../components/hutubiao/tubiao.vue";
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers("licai");
export default {
  components: {
    Head,
    Car,
    Tubiao,
  },
  computed: {
    ...mapState(["regularDetail", "regularMinuteProduct", "time"]),
  },
  onLoad(ops) {
    console.log(ops, 555555555555);
    wx.setNavigationBarTitle({
      title: ops.name,
    });
	(this.ids = ops.id), (this.name = ops.name);
    // console.log(222222,this.ids,this.name)

    this.getregularDetails({
      id: ops.id,
    });
    this.getregularMinuteProducts({
      id: ops.id,
    });
    this.getcurrentTimes({
      time: "1",
    });
  },
  data() {
    return {
      ids: "",
      times: "1",
      name: "",
      codetext: [
        {
          t: "月",
          code: true,
        },
        {
          t: "季",
          code: false,
        },
        {
          t: "半年",
          code: false,
        },
        {
          t: "年",
          code: false,
        },
      ],
    };
  },
  methods: {
    ...mapActions([
      "getregularDetails",
      "getregularMinuteProducts",
      "getcurrentTimes",
    ]),
    bought(ids, names) {

 if (!uni.getStorageSync("token")) {
        uni.showModal({
          title: "提示",
          content: "请登录后购买",
          success: function (res) {
            if (res.confirm) {
              console.log("用户点击确定");
              uni.navigateTo({
                url: "/pages/login/login",
              });
            }
          },
        });
      } else if (
        uni.getStorageSync("userAssessmentLevel") == "未评测" &&
        uni.getStorageSync("token")
      ) {
        uni.showModal({
          title: "提示",
          content:
            "根据金融监管机构要求，在您投资前先完成风险测评问卷，进一步了解自身的投资风险及风险承受能力（预计[耗时80秒]）。在您购买产品时，我们将根据测评结果，进行风险等级匹配检查和风险提示，请您关注。",
          success: function (res) {
            if (res.confirm) {
              console.log("用户点击确定");
              uni.navigateTo({
                url: "/pages/appraisal/appraisal",
              });
            } else if (res.cancel) {
              console.log("用户点击取消");
            }
          },
        });
      } else  if (uni.getStorageSync("userAuthenticationStatus")=='未认证') {
        uni.showModal({
          title: "提示",
          content: "请进行身份认证后购买",
          success: function (res) {
            if (res.confirm) {
              console.log("用户点击确定");
              uni.navigateTo({
                url: "/pages/idDocument/idDocument",
              });
            }
          },
        });
      }else {
            uni.navigateTo({
		url: "../buy/buy1/buy1?id=" + ids + "&name=" + names
		+'&money='+this.regularDetail.regularProductMoney
      });
      }

  
    },
    change(t) {
      this.codetext.map((item, index) => {
        item.code = false;
        if (t == item && item.t == "月") {
          this.times = "1";
          this.getcurrentTimes({
            time: this.times,
          });
          this.getregularMinuteProducts({
            id: this.ids,
          });
          item.code = !item.code;
        } else if (t == item && item.t == "季") {
          this.times = "2";
          this.getcurrentTimes({
            time: this.times,
          });
          this.getregularMinuteProducts({
            id: this.ids,
          });
          item.code = !item.code;
        } else if (t == item && item.t == "半年") {
          this.times = "3";
          this.getcurrentTimes({
            time: this.times,
          });
          this.getregularMinuteProducts({
            id: this.ids,
          });
          item.code = !item.code;
        } else if (t == item && item.t == "年") {
          this.times = "4";
          this.getcurrentTimes({
            time: this.times,
          });
          this.getregularMinuteProducts({
            id: this.ids,
          });
          item.code = !item.code;
        }
        return item;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.but {
  margin-top: 24rpx;
  width: 90%;
  margin: 24px auto;
  height: 94rpx;
  border-radius: 16rpx;
  background-color: #ff4658;
  color: #ffffff;
  text-align: center;
  line-height: 94rpx;
  font-size: 36rpx;
}

.texts {
  padding: 0px 24rpx;
  color: #015dfb;
  font-size: 20rpx;
}

.text {
  height: 50rpx;
  width: 100%;
  margin: 20rpx auto;

  text-align: center;
  font-size: 24rpx;
  color: #ff623c;
}

.fenlei {
  height: 60rpx;
  width: 90%;
  margin: 20rpx auto;
  border: 1px solid #cdcdcd;
  border-radius: 20rpx;
  display: flex;

  view {
    width: 25%;
    text-align: center;
    line-height: 60rpx;
    border-right: 1px solid #cdcdcd;
  }
}

.xuanzhong {
  background-color: #ff4658;
  color: #ffffff;
  border-radius: 20rpx;
}
</style>
